'use strict';
const dayjs = require("dayjs");
module.exports = app => {
  const { STRING, INTEGER } = app.Sequelize;
    const Model = app.model.define(
      'staffComment',
      {
          id: {type: INTEGER, primaryKey: true, autoIncrement: true},
          /**
           * `staff_id` int(11) DEFAULT NULL COMMENT '客服',
           *   `member_id` int(11) DEFAULT NULL COMMENT '用户',
           *   `score` int(11) DEFAULT 0 COMMENT '评分',
           *   `comment` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '评论',
           *   `status` int(11) DEFAULT 1 COMMENT '审核状态',
           *   `is_del` int(11) DEFAULT 0 COMMENT '是否删除',
           */
            anony: {type: INTEGER, allowNull: false, defaultValue: 1, comment: '是否匿名'},
            order_id: {type: INTEGER, allowNull: true, comment: '订单'},
            order_no: {type: STRING(255), allowNull: false, comment: '订单号'},
            staff_id: {type: INTEGER, allowNull: false, comment: '客服'},
            member_id: {type: INTEGER, allowNull: false, comment: '用户'},
            score: {type: INTEGER, allowNull: false, defaultValue: 0, comment: '评分'},
            comment: {type: STRING(255), allowNull: false, comment: '评论'},
            status: {type: INTEGER, allowNull: false, defaultValue: 1, comment: '审核状态'},
            is_del: {type: INTEGER, allowNull: false, defaultValue: 0, comment: '是否删除'},
          create_time: {
              type: app.Sequelize.DATE,
              allowNull: false,
              get() {
                  return dayjs(this.getDataValue('create_time')).format('YYYY-MM-DD HH:mm:ss');
              },
          },
      },
      {
          tableName: 'staff_comment',
          timestamps: true, // 启用时间戳(createdAt, updatedAt)
          updatedAt: 'updated_time', // 不想要 updatedAt
          createdAt: 'create_time', // 想要  createdAt 但是希望名称叫做 created_at
      }
  );
    Model.associate = function() {
        app.model.StaffComment.belongsTo(app.model.Staff, { foreignKey: 'staff_id', targetKey: 'id' });
        app.model.StaffComment.belongsTo(app.model.Member, { foreignKey: 'member_id', targetKey: 'id' });
        app.model.StaffComment.belongsTo(app.model.OrderGoods, { foreignKey: 'order_id', targetKey: 'id'});
    }
    return Model
};
